package com.example.demo.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.Util.WebSocket;
import com.example.demo.wuliu.tablepojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
public class test1 {


    @Resource
    private WebSocket webSocket;


    @ResponseBody
    @GetMapping("/daping")
    public void gettable(String userId){

        System.out.println(userId);


        //创建业务消息信息
        JSONObject obj = new JSONObject();
        obj.put("cmd", "topic");//业务类型
        obj.put("msgId", userId);//消息id
        obj.put("msgTxt", "dfadsfsacasfa案件非常差那上次");//消息内容
//全体发送
        //webSocket.sendAllMessage(obj.toJSONString());
//单个用户发送 (userId为用户id)
        webSocket.sendOneMessage(userId, obj.toJSONString());
////多个用户发送 (userIds为多个用户id，逗号‘,’分隔)
       // webSocket.sendMoreMessage(new String[]{userId, "33"}, obj.toJSONString());



    }

}
